package am;

public class Person {
    private String name;
    private int age ;
    private String gerden;

    public Person(String name, int age, String gerden) {
        this.name = name;
        this.age = age;
        this.gerden = gerden;
    }

    public int getAge() {
        return age;
    }

    @Override
    public String toString() {
        return "Person{" +
                "姓名：" + name + '\'' +
                ", 年龄：" + age +
                ", 性别：" + gerden + '\'' +
                '}';
    }
}

class Student{
    private Person[] pre;
    
    public Student(){
        pre = new Person[3];
        pre[0] = new Person("张三",28,"男");
        pre[1] = new Person("李四",18,"女");
        pre[2] = new Person("王五",36,"男");
    }
    public  void changeSore(){
        for (int i = 0; i < pre.length - 1; i++) {
            Person current = pre[i + 1];
            int index = i; // 认为已经排好序的最大下标
            // 结束的条件是 index < 0 或者 current 大于 arr[index]
            for (;index >= 0 && current.getAge() > pre[index].getAge(); index--) {
                pre[index + 1] = pre[index];
            }
            pre[index + 1] = current;
        }
        for (int i = 0; i < pre.length ; i++) {
            System.out.println(pre[i]);
        }
    }
}
class Test{
    public static void main(String[] args) {
        Student stu = new Student();
        stu.changeSore();
    }
    
}
